package com.doyle.musicplus.client;

import com.doyle.musicplus.shared.SimpleCallback;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.*;


public class LoginFormView extends View implements LoginFormPresenter.LoginFormDisplay {
	
	AsyncCallback<Object> loginCallback;
	final TextBox nameTextBox = new TextBox();
	final TextBox passwordTextBox = new PasswordTextBox();
	final Button loginButton = new Button("Log In");
	final FlexTable flex = new FlexTable();
	@SuppressWarnings("deprecation")
	final DockLayoutPanel dock = new DockLayoutPanel(Unit.EM);
	
	public LoginFormView() {
		loginButton.addClickHandler(new ClickHandler() {
			public void onClick(final ClickEvent event) {
				loginCallback.onSuccess(null);
			}
		});
		
		flex.setWidget(0, 0, new Label("User Name:"));
		flex.setWidget(0, 1, nameTextBox);
		flex.setWidget(1, 0, new Label("Password:"));
		flex.setWidget(1, 1, passwordTextBox);
		flex.setWidget(2, 1, loginButton);
		
		dock.setWidth("100%");
		dock.setHeight("100%");
		dock.add(flex);
		
		initWidget(dock);
		
	}
	
	public final String getName() {
		return nameTextBox.getValue();
	}
	
	public final String getPassword() {
		return passwordTextBox.getValue();
	}
	
	public final void setName(final String s) {
		nameTextBox.setValue(s);
	}
	
	public final void setPassword(final String s) {
		passwordTextBox.setValue(s);
	}
	
	public final void setLoginCallback(final SimpleCallback<Object> acb) {
		loginCallback = acb;
	}
	
	public final Widget asWidget() {
		return LoginFormView.this;
	}
	
	
	
}
